<?php

namespace App\Observers;

use App\Models\RentandPurchase;
use App\Services\ElasticSearchService;
use App\Services\OrderService;
use App\Tools\RedisHouseList;
use App\Tools\TxdtTools;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis;

class RentAndPurchaseObserver
{
    /**
     * Handle the RentandPurchase "created" event.
     *
     * @param  \App\Models\RentandPurchase  $rentandPurchase
     * @return void
     */
    public function created(RentandPurchase $rentandPurchase)
    {
        $user = RentAndPurchase::with('userModel')->where('id',$rentandPurchase->id)->where('uid',$rentandPurchase->uid)->first()->toArray();
        $user['user_image']=$user['user_model']['user_image'];
        $user['user_model']=$user['user_model']['user_name'];
        (new RedisHouseList())->HashList($user);
        $tx = (new TxdtTools())->addressName($rentandPurchase->house_region);
        $rentAnd = RentAndPurchase::where('id',$rentandPurchase->id)->first();
        $rentAnd->update(['house_region'=>$tx]);
        OrderService::createOrder($rentandPurchase->uid,"10","3",$rentandPurchase->id);

    }

    /**
     * Handle the RentandPurchase "updated" event.
     *
     * @param  \App\Models\RentandPurchase  $rentandPurchase
     * @return void
     */
    public function updated(RentandPurchase $rentandPurchase)
    {

    }

    /**
     * Handle the RentandPurchase "deleted" event.
     *
     * @param  \App\Models\RentandPurchase  $rentandPurchase
     * @return void
     */
    public function deleted(RentandPurchase $rentandPurchase)
    {
        //
    }

    /**
     * Handle the RentandPurchase "restored" event.
     *
     * @param  \App\Models\RentandPurchase  $rentandPurchase
     * @return void
     */
    public function restored(RentandPurchase $rentandPurchase)
    {
        //
    }

    /**
     * Handle the RentandPurchase "force deleted" event.
     *
     * @param  \App\Models\RentandPurchase  $rentandPurchase
     * @return void
     */
    public function forceDeleted(RentandPurchase $rentandPurchase)
    {
        //
    }

}
